package twoD.IsoPfem.math;

public class ShapeFunctionOnQT implements FunctionBasisOnR3 {

	private static final int d_ = 6;
	private Interval interval_ = new Interval(0, 1);
	private FunctionR3ToR[] N_;

	public ShapeFunctionOnQT() {
		N_ = new FunctionR3ToR[d_];
		N_[0] = new FunctionR3ToR() {

			@Override
			public double valueAt(double xi1, double xi2, double xi3) {
				return xi1 * (2 * xi1 - 1);
			}

			@Override
			public double[] gradientAt(double xi1, double xi2, double xi3) {
				return new double[] { 4 * xi1 - 1, 0, 0 };
			}
		};
		N_[1] = new FunctionR3ToR() {

			@Override
			public double valueAt(double xi1, double xi2, double xi3) {
				return xi2 * (2 * xi2 - 1);
			}

			@Override
			public double[] gradientAt(double xi1, double xi2, double xi3) {
				return new double[] { 0, 4 * xi2 - 1, 0 };
			}
		};
		N_[2] = new FunctionR3ToR() {

			@Override
			public double valueAt(double xi1, double xi2, double xi3) {
				return xi3 * (2 * xi3 - 1);
			}

			@Override
			public double[] gradientAt(double xi1, double xi2, double xi3) {
				return new double[] { 0, 0, 4 * xi3 - 1 };
			}
		};
		N_[3] = new FunctionR3ToR() {

			@Override
			public double valueAt(double xi1, double xi2, double xi3) {
				return 4 * xi1 * xi2;
			}

			@Override
			public double[] gradientAt(double xi1, double xi2, double xi3) {
				return new double[] { 4 * xi2, 4 * xi1, 0 };
			}
		};
		N_[4] = new FunctionR3ToR() {

			@Override
			public double valueAt(double xi1, double xi2, double xi3) {
				return 4 * xi2 * xi3;
			}

			@Override
			public double[] gradientAt(double xi1, double xi2, double xi3) {
				return new double[] { 0, 4 * xi3, 4 * xi2 };
			}
		};
		N_[5] = new FunctionR3ToR() {

			@Override
			public double valueAt(double xi1, double xi2, double xi3) {
				return 4 * xi1 * xi3;
			}

			@Override
			public double[] gradientAt(double xi1, double xi2, double xi3) {
				return new double[] { 4 * xi3, 0, 4 * xi1 };
			}
		};
	}

	@Override
	public FunctionR3ToR getBasisFunction(int i) {
		return N_[i];
	}

	@Override
	public FunctionR3ToR[] getBasisFunctions() {
		return N_;
	}

	@Override
	public double[] getBreakpoints() {
		return null;
	}

	@Override
	public int getDimension() {
		return d_;
	}

	@Override
	public Interval getDomain() {
		return interval_;
	}

	@Override
	public int getP() {
		return 2;
	}
}
